<template>
  <div class="container-content">
    <el-form
      ref="formRef"
      :model="formObject"
      label-width="100px"
      label-position="left"
      :rules="rules"
    >
      <el-collapse v-model="activeNames">
        <el-collapse-item title=" 基本信息" name="1">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="合同类型">
                <el-select
                  v-model="formObject.contractProcureEntity.procureType"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <!-- @change="getContractTypeOptions" -->
                  <el-option
                    v-for="item in typeOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同模版">
                <el-select
                  v-model="contractType"
                  placeholder="请选择"
                  style="width: 100%"
                  @change="getContractContent"
                >
                  <el-option
                    v-for="item in contractTypeOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同名称">
                <el-input
                  v-model="formObject.contractProcureEntity.contractName"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购部门">
                <el-input v-model="formObject.contractProcureEntity.deptName">
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('deptId')"
                  ></i
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
              <el-collapse-item title="供应商信息" name="2">
               <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item
                label="项目"
                prop="contractProcureEntity.projectName"
              >
                <el-input
                  v-model="formObject.contractProcureEntity.projectName"
                  
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('project')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="供应商"
                prop="contractProcureEntity.supplierName"
              >
                <el-input
                  v-model="formObject.contractProcureEntity.supplierName"
                  

                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('supplier')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供货方">
                <el-input
                  v-model="formObject.contractProcureEntity.supplierGoodsName"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('supplierGoods')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供货方联系人">
                <el-input
                  v-model="formObject.contractProcureEntity.supplierContactName"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('supplierContact')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系人职务">
                <el-input
                  v-model="formObject.contractProcureEntity.contactPosition"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系人手机号">
                <el-input
                  v-model="formObject.contractProcureEntity.telPhone"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供货方地址">
                <el-input
                  v-model="formObject.contractProcureEntity.supplierAddress"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结算方">
                <el-input
                  v-model="formObject.contractProcureEntity.settlementName"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('settlement')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="收款方">
                <el-input
                  v-model="formObject.contractProcureEntity.payableName"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('payable')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="邮箱">
                <el-input
                  v-model="formObject.contractProcureEntity.email"
                  clearable
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="change ? '变更原因' : '备注'">
                <el-input
                  v-model="formObject.contractProcureEntity.remarks"
                  type="textarea"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="财务信息" name="3">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item
                label="付款方式"
                prop="contractProcureEntity.payTypeName"
              >
                <el-input
                  v-model="formObject.contractProcureEntity.payTypeName"
                  
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('pay')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="保证金金额" label-width="110px">
                <el-input
                  v-model="formObject.contractProcureEntity.marginMoney"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结算币别">
                <el-input
                  v-model="
                    formObject.contractProcureEntity.settlementCurrencyName
                  "
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('currency')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="汇率">
                <el-input
                  v-model="formObject.contractProcureEntity.rate"
                  clearable
                  @change="changeRate"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="定价时点">
                <el-select
                  v-model="formObject.contractProcureEntity.priceTimePoint"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option :key="1" label="系统日期" :value="1"> </el-option>
                  <el-option :key="2" label="单据日期" :value="2"> </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="本位币">
                <el-input
                  v-model="
                    formObject.contractProcureEntity.standardCurrencyName
                  "
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('standardCurrency')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="付款条件">
                <el-input
                  v-model="formObject.contractProcureEntity.paymentTermsName"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('paymentTerms')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="合同总金额本位币" label-width="150px">
                <el-input
                  v-model="formObject.contractProcureEntity.totalAmountCurrency"
                  clearable
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="汇率类型">
                <el-input
                  v-model="formObject.contractProcureEntity.rateType"
                  clearable
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('rateType')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="签订日期">
                <el-date-picker
                  v-model="formObject.contractProcureEntity.signTime"
                  type="date"
                  placeholder="选择日期"
                  style="width: 100%"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开始日期">
                <el-date-picker
                  v-model="formObject.contractProcureEntity.startTime"
                  type="date"
                  placeholder="选择日期"
                  style="width: 100%"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结束日期">
                <el-date-picker
                  v-model="formObject.contractProcureEntity.endTime"
                  type="date"
                  placeholder="选择日期"
                  style="width: 100%"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="是否含税">
                <el-radio
                  border
                  :label="1"
                  v-model="formObject.contractProcureEntity.isIncludeTax"
                  >是</el-radio
                >
                <el-radio
                  border
                  :label="2"
                  v-model="formObject.contractProcureEntity.isIncludeTax"
                  >否</el-radio
                >
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否价外税">
                <el-radio
                  border
                  :label="1"
                  v-model="formObject.contractProcureEntity.isExtraPriceTax"
                  >是</el-radio
                >
                <el-radio
                  border
                  :label="2"
                  v-model="formObject.contractProcureEntity.isExtraPriceTax"
                  >否</el-radio
                >
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title=" 合同模板" name="4">
          <Editor
            ref="editor"
            editor-id="editor"
            height="500px"
            :template-content="formObject.contractProcureEntity.contractContent"
          />
        </el-collapse-item>
        <el-collapse-item title=" 明细信息" name="5">
          <template v-if="formObject.contractProcureEntity.procureType !== 2">
            <div class="desc-title">物料列表</div>
            <div class="floatright mb10">
              <el-button type="primary" plain @click="showDialog('order')"
                >选单</el-button
              >

              <el-button
                type="primary"
                plain
                @click="showDialog('material', -1)"
                >导入物料</el-button
              >
            </div>
            <el-table
              :data="formObject.materialDetailEntities"
              style="width: 100%"
              highlight-current-row
              border
            >
              <template #empty>
                <el-button
                  plain
                  type="primary"
                  round
                  @click="addNewRow('material')"
                  >添加新行
                </el-button>
              </template>
              <el-table-column label="操作" width="120" fixed>
                <template slot-scope="scope">
                  <el-button
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleDataAdd_material(scope.$index, scope.row)"
                  ></el-button>
                  <el-button
                    plain
                    icon="el-icon-minus"
                    size="mini"
                    @click="
                      handleDataDelete(scope.$index, scope.row, 'material')
                    "
                  ></el-button>
                </template>
              </el-table-column>
              <el-table-column
                type="index"
                label="序号"
                width="50"
              ></el-table-column>
              <el-table-column>
                <template slot="header">
                  物料编码<span class="required">*</span>
                </template>
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                    :rules="rules.materialCode"
                    :prop="
                      'materialDetailEntities.' + scope.$index + '.materialCode'
                    "
                  >
                    <el-input
                      v-model="scope.row.materialCode"
                      clearable
                    >
                      <i
                        slot="suffix"
                        class="el-input__icon el-icon-notebook-2"
                        style="cursor: pointer"
                        @click="showDialog('material', scope.$index)"
                      ></i>
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="物料名称">
                <template slot-scope="scope">
                  <el-form-item
                    prop="materialName"
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.materialName"
                      clearable
                      disabled
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="规格型号">
                <template slot-scope="scope">
                  <el-form-item
                    prop="model"
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input v-model="scope.row.model" clearable disabled>
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>

              <el-table-column>
                <template slot="header">
                  采购单位<span class="required">*</span>
                </template>
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.purchaseUnit"
                      clearable
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column>
                <template slot="header">
                  计价单位<span class="required">*</span>
                </template>
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.pricingUnit"
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="计价数量">
                <template slot-scope="scope">
                  <el-form-item
                    prop="pricingNum"
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input v-model="scope.row.pricingNum" clearable>
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="单价">
                <template slot-scope="scope">
                  <el-form-item
                    prop="price"
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input v-model="scope.row.price" disabled clearable>
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="交货日期">
                <template slot-scope="scope">
                  <el-form-item
                    prop="deliveryDate"
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.deliveryDate"
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="含税单价">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input v-model="scope.row.taxPrice" disabled clearable>
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="折扣率%">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.discountRate"
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="折扣额">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.discountAmount"
                      disabled
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="金额">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.amountMoney"
                      disabled
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="数量">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.number"
                      clearable
                      @change="caculateNum(scope.row, scope.$index)"
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="税率%">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.taxRate"
                      clearable
                      @change="caculateNum(scope.row, scope.$index)"
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="税额">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input v-model="scope.row.taxAmount" disabled clearable>
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="价税合计">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.totalTaxPrice"
                      clearable
                      @change="caculateNum(scope.row, scope.$index)"
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>

              <el-table-column label="需求组织">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.requireDept"
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="收料组织">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.receivingDept"
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column>
                <template slot="header">
                  结算组织<span class="required">*</span>
                </template>
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.settlementDept"
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="是否赠品">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-checkbox
                      v-model="scope.row.isGiveaway"
                    ></el-checkbox>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="备注">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.ramarks"
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column>
                <template slot="header">
                  库存单位<span class="required">*</span>
                </template>
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.inventoryUnit"
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </template>
              </el-table-column>

              <el-table-column label="库存数量">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.inventoryNum"
                      clearable
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>

              <el-table-column label="先收票数量(库存基本)">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.receivedFirstTicketsNum"
                      clearable
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="供应商物料编码">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.supplierMaterialCode"
                      clearable
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="供应商物料名称">
                <template slot-scope="scope">
                  <el-form-item
                    label-width="0px"
                    style="margin: 0"
                  >
                    <el-input
                      v-model="scope.row.supplierMaterialName"
                      clearable
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-collapse-item>
      </el-collapse>

      <!-- 订单列表 -->
      <!-- <div class="desc-title">订单列表</div> -->

      <!-- <el-table
                :data="formObject.orderEntities"
                style="width: 100%"
                highlight-current-row
                border
            >
                <template #empty>
                    <el-button
                        plain
                        type="primary"
                        round
                        @click="addNewRow('order')"
                        >添加新行
                    </el-button>
                </template>
                <el-table-column label="操作" width="120">
                    <template slot-scope="scope">
                        <el-button
                            plain
                            icon="el-icon-plus"
                            size="mini"
                            @click="
                                handleDataAdd_order(scope.$index, scope.row)
                            "
                        ></el-button>
                        <el-button
                            plain
                            icon="el-icon-minus"
                            size="mini"
                            @click="
                                handleDataDelete(
                                    scope.$index,
                                    scope.row,
                                    'order'
                                )
                            "
                        ></el-button>
                    </template>
                </el-table-column>
                <el-table-column label="单据编号">
                    <template slot-scope="scope">
                        <el-form-item
                            prop="orderNumber"
                            label-width="0px"
                            style="margin: 0"
                        >
                            <el-input v-model="scope.row.orderNumber" clearable>
                                <i
                                    slot="suffix"
                                    class="el-input__icon el-icon-notebook-2"
                                    style="cursor: pointer"
                                    @click="getOrderLists(scope.$index)"
                                ></i>
                            </el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column label="采购日期">
                    <template slot-scope="scope">
                        <el-form-item
                            prop="applyTime"
                            label-width="0px"
                            style="margin: 0"
                        >
                            <el-date-picker
                                v-model="scope.row.applyTime"
                                type="date"
                                clearable
                                placeholder="选择日期"
                                style="width: 100%"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column label="供应商">
                    <template slot-scope="scope">
                        <el-form-item
                            prop="supplierName"
                            label-width="0px"
                            style="margin: 0"
                        >
                            <el-input
                                v-model="scope.row.supplierName"
                                clearable
                            ></el-input>
                        </el-form-item>
                        
                    </template>
                </el-table-column>
                <el-table-column label="关闭状态">
                    <template slot-scope="scope">
                        <el-form-item
                            prop="closeState"
                            label-width="0px"
                            style="margin: 0"
                        >
                            <el-input
                                v-model="scope.row.closeState"
                                clearable
                            ></el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column label="订单金额">
                    <template slot-scope="scope">
                        <el-form-item
                            prop="money"
                            label-width="0px"
                            style="margin: 0"
                        >
                            <el-input v-model="scope.row.money"></el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
            </el-table> -->
      <!-- 物料列表 -->
    </el-form>
    <!-- 弹窗 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="open"
      append-to-body
      width="70%"
    >
      <!-- 项目列表 -->
      <el-table
        border
        v-loading="loading"
        v-if="dialogType === 'project'"
        ref="tableRef"
        :data="tableData"
        @selection-change="selectProjectItem"
      >
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>
        <el-table-column type="index" width="55" align="center">
        </el-table-column>
        <el-table-column prop="deptName" label="部门名称"></el-table-column>
        <el-table-column prop="projectName" label="项目名称"></el-table-column>
      </el-table>
      <!-- 供应商列表 -->
      <el-table
        border
        v-if="dialogType === 'supplier'"
        v-loading="loading"
        ref="tableRef"
        :data="tableData"
        @selection-change="selectSupplyItem"
      >
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>
        <el-table-column
          prop="supplierCode"
          label="	供应商编码"
        ></el-table-column>
        <el-table-column
          prop="supplierName"
          label="供应商名称"
        ></el-table-column>
        <el-table-column prop="group" label="供应商分组"></el-table-column>
        <el-table-column
          prop="classification"
          label="供应商分类"
        ></el-table-column>
        <el-table-column prop="level" label="供应商等级"> </el-table-column>
        <el-table-column
          prop="defaultContracts"
          label="默认联系人"
        ></el-table-column>
      </el-table>
      <!-- 订单列表 -->
      <el-table
        v-if="dialogType === 'order'"
        v-loading="loading"
        ref="tableRef"
        :data="tableData"
        @selection-change="selectOrdertem"
        border
      >
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>
        <el-table-column prop="materialCode" label="物料编码"></el-table-column>
        <el-table-column prop="materialName" label="物料名称"></el-table-column>
        <el-table-column prop="model" label="规格型号"> </el-table-column>
        <el-table-column prop="number" label="数量"></el-table-column>
        <el-table-column prop="taxRate" label="税率"></el-table-column>
        <el-table-column prop="taxMoney" label="含税金额"></el-table-column>
        <el-table-column prop="noTaxMoney" label="不含税金额"></el-table-column>
      </el-table>
      <!-- 物料列表 -->
      <el-table
        border
        v-if="dialogType === 'material'"
        v-loading="loading"
        ref="tableRef"
        :data="tableData"
        @selection-change="selectMaterialtem"
      >
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>
        <!-- <el-table-column prop="id" label="id"> </el-table-column> -->
        <el-table-column prop="materialName" label="物料名称"></el-table-column>
        <el-table-column prop="materialCode" label="物料编码"></el-table-column>
        <el-table-column prop="typeName" label="分类名称"></el-table-column>
        <el-table-column prop="unit" label="单位"></el-table-column>
        <el-table-column prop="model" label="规格型号"> </el-table-column>
        <el-table-column prop="paramDesc" label="参数说明"> </el-table-column>
        <el-table-column prop="brand" label="品牌"></el-table-column>
        <el-table-column prop="type" label="物料类型">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.type == '1'">自购物料</el-tag>
            <el-tag v-if="scope.row.type == '2'">甲购物料</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <!-- 付款方式 -->
      <el-table
        border
        v-loading="loading"
        v-if="dialogType === 'pay'"
        ref="tableRef"
        :data="tableData"
        @selection-change="selectProjectItem"
      >
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>
        <el-table-column prop="typeName" label="付款方式"></el-table-column>
        <el-table-column prop="createTime" label="创建时间"></el-table-column>
      </el-table>
      <!-- 采购部门 -->
      <el-table
        ref="customerTable"
        :data="tableData"
        stripe
        style="width: 100%"
        v-if="dialogType === 'deptId'"
        @row-dblclick="selectProjectItem"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column type="index" label="序号" width="55" align="center" />
        <el-table-column prop="deptCode" label="部门编码">
          <template slot-scope="scope">{{
            scope.row.deptCode || "--"
          }}</template>
        </el-table-column>
        <el-table-column prop="deptName" label="部门名称">
          <template slot-scope="scope">{{
            scope.row.deptName || "--"
          }}</template>
        </el-table-column>
        <el-table-column prop="orderNum" label="排序">
          <template slot-scope="scope">{{
            scope.row.orderNum || "--"
          }}</template>
        </el-table-column>
        <el-table-column prop="email" label="邮箱">
          <template slot-scope="scope">{{ scope.row.email || "--" }}</template>
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === '0'" type="success">正常</el-tag>
            <el-tag v-if="scope.row.status === '1'" type="danger">异常</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="手机"
          ><template slot-scope="scope">{{
            scope.row.phone || "--"
          }}</template></el-table-column
        >
      </el-table>
      <el-table
        ref="currencyTable"
        :data="tableData"
        stripe
        style="width: 100%"
        v-if="dialogType === 'rateType'"
        @row-dblclick="selectProjectItem"
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
        ></el-table-column>
        <el-table-column
          type="index"
          label="序号"
          width="55"
          align="center"
        ></el-table-column>
        <el-table-column prop="code" label="编码">
          <template slot-scope="scope">
            <span>{{ scope.row.code || "--" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="名称">
          <template slot-scope="scope">
            <span>{{ scope.row.name || "--" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="directRateAccuracy" label="直接汇率精度">
          <template slot-scope="scope">
            <span>{{ scope.row.directRateAccuracy || "--" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="indirectRateAccuracy" label="间接汇率精度">
          <template slot-scope="scope">
            <span>{{ scope.row.indirectRateAccuracy || "--" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="isSystem" label="是否系统预设">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.isSystem">是</el-tag>
            <el-tag v-else-if="!scope.row.isSystem">否</el-tag>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="userId" label="录入人">
          <template slot-scope="scope">
            <span>{{ scope.row.userId || "--" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="changeId" label="修改人">
          <template slot-scope="scope">
            <span>{{ scope.row.changeId || "--" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="describe" label="描述">
          <template slot-scope="scope">
            <span>{{ scope.row.describe || "--" }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="pagination mt20"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelSelect">取 消</el-button>
        <el-button type="primary" @click="confirmSelect">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  getList,
  addProcure,
  editProcureList,
  getDetailProcure,
  saveProcure, //采购暂存
  submitProcure, //采购提交
} from "@/api/system/contract";
import { getProjectList } from "@/api/system/project";
import { getSupplyList } from "@/api/system/supply";
import Editor from "../../editor/index.vue";
import { convertToRMB } from "@/utils/utils";
import {
  getOrderList,
  getContractMaterialLists,
  getMaterialList,
  getOrderDetail,
} from "@/api/system/purchase";
import { getPayType } from "@/api/base/data";
import { getCompute } from "@/api/finance/info";
import { listDept } from "@/api/system/dept";
import { getExchangeTypeData } from "@/api/base/data";
export default {
  components: {
    Editor,
  },
  props: { id: String, change: Boolean },
  data() {
    return {
      limit: 10,
      page: 1,
      activeNames: ["1", "2", "3", "5"],
      contractType: "",
      contractTypeOptions: [],
      currentIndex: "", //订单列表 物料列表 当前索引
      formObject: {
        contractProcureEntity: {
          contractContent: "",
          contractName: "",
          contractNumber: "",
          createBy: "",
          createTime: "",
          deptId: "",
          id: "",

          marginMoney: "",
          marginRate: "",
          money: "",
          moneyUpper: "",
          params: {},
          payType: "",
          payTypeName: "",
          projectId: "",
          projectName: "",
          remark: "",
          remarks: "",
          searchValue: "",
          signTime: "",
          supplierId: "",
          supplierName: "",
          taxMoney: "",
          taxRate: "",
          type: 1,
          procureType: "",
          updateBy: "",
          updateTime: "",
        },

        orderEntities: [],
        materialDetailEntities: [],
      },
      rules: {
        materialCode: [
          {
            required: true,
            message: "请输入物料编码",
            trigger: "blur",
          },
        ],
        purchaseUnit: [
          {
            required: true,
            message: "请输入采购单位",
            trigger: "blur",
          },
        ],
        pricingUnit: [
          {
            required: true,
            message: "请输入计价单位",
            trigger: "blur",
          },
        ],
        settlementDept: [
          {
            required: true,
            message: "请输入结算组织",
            trigger: "blur",
          },
        ],
        inventoryUnit: [
          {
            required: true,
            message: "请输入库存单位",
            trigger: "blur",
          },
        ],
        contractProcureEntity: {
          contractName: [
            {
              required: true,
              message: "请输入合同名称",
              trigger: "blur",
            },
          ],
          supplierName: [
            {
              required: true,
              message: "请选择供应商",
              trigger: "blur",
            },
          ],
          procureType: [
            {
              required: true,
              message: "请选择合同类型",
              trigger: "blur",
            },
          ],
        },
      },
      typeOptions: [
        {
          label: "普通合同",
          value: 1,
        },
        {
          label: "框架合同",
          value: 2,
        },
        {
          label: "单价合同",
          value: 3,
        },
      ],
      open: false,
      tableData: [],
      total: 0,
      dialogTitle: "",
      loading: true,
      dialogType: "",
      selectItem: [],
    };
  },
  methods: {
    getContractContent(val) {
      this.formObject.contractProcureEntity.contractContent =
        this.contractTypeOptions.find((item) => item.id == val).content;
    },
    // 表单提交
    onSubmit(cb, val) {
      this.$refs["formRef"].validate((valid) => {
        if (!valid) {
          // cb();
          this.$message.error("请完整填写信息！");
          return;
        }
          // 修改
            editProcureList(this.formObject).then((res) => {
              if (res.code === 200) {
                cb();
                this.$message({
                  message: "修改成功！",
                  type: "success",
                });
              }
            });
            })
    },
    // 表单重置
    resetForm() {
      this.$refs["formRef"].resetFields();
    },

    // 数字金额转大写
    changeMoney() {
      this.formObject.contractProcureEntity.moneyUpper = convertToRMB(
        this.formObject.contractProcureEntity.money * 1
      );
    },
    // 获取详情回显
    getDetailData(id) {
      getDetailProcure(id).then((res) => {
        this.formObject = res.data;
        // this.getContractTypeOptions(res.data.type);
      });
    },
    // 新增物料列表
    handleDataAdd_material(index, row) {
      let materialObj = {
        amountMoney: "",
        batchNum: "",
        businessTaxCostPrice: "",
        changeTime: "",
        changeType: "",
        containsTaxPrice: "",
        createTime: "",
        deliveryAddress: "",
        deliveryDate: "",
        deliveryLocation: "",
        discountAmount: "",
        discountRate: "",
        executeStatus: "",
        id: "",
        sourceMaterialDetailId: "",
        inventoryId: "",
        inventoryNum: 0,
        inventoryUnit: "",
        isGiveaway: true,

        limit: 0,
        material: {
          allowAsset: "",
          allowInventory: "",
          allowOutsource: "",
          allowProduce: "",
          allowPurchase: "",
          allowSale: "",
          barCode: "",
          brand: "",
          businessType: "",
          configurationProduction: "",
          costPriceRatio: "",
          createBy: "",
          createTime: "",
          dataState: "",
          defaultTaxRate: "",
          deptId: "",
          disableBy: "",
          examineBy: "",
          examineTime: "",
          grossWeight: "",
          heightStr: "",
          id: "",
          imgUrl: "",
          instanceId: "",
          inventoryType: "",
          isChange: "",

          kit: "",
          lengthStr: "",
          materialCode: "",
          materialDesc: "",
          materialGroup: "",
          materialInventoryEntity: {
            batchInfo: "",
            batchRule: "",
            checkCycle: "",
            convertDirection: "",
            costUnit: "",
            createBy: "",
            createTime: "",
            currency: "",
            day: "",
            economicOrderingBatch: "",
            id: "",
            inventoryUnit: "",
            isBatch: "",
            isCheck: "",
            isLock: "",
            isMaxInventory: "",
            isMinInventory: "",
            isOrderGoods: "",
            isSafeInventory: "",
            isTrueCheck: "",
            materialId: "",
            maxInventoyNum: "",
            minInventoryNum: "",
            orderGoodsNum: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            qualityManage: "",
            qualityNum: "",
            qualityUnit: "",
            referenceCost: "",
            remark: "",
            safeInventoryNum: "",
            searchValue: "",
            serviceLife: "",
            standardNumber: "",
            supportUnit: "",
            updateBy: "",
            updateTime: "",
            warePosition: "",
            warehouseCode: "",
          },
          materialName: "",
          materialPlanAttributeEntity: {
            createBy: "",
            createTime: "",
            fAllowPartDelay: "",
            fBaseVarLeadTimeLotSize: "",
            fBaseVarLeadTimeLotSizeUnit: "",
            fCanDelayDays: 0,
            fCanLeadDays: 0,
            fCheckLeadTime: 0,
            fCheckLeadTimeType: "",
            fDelayExtendDay: 0,
            fFixLeadTime: 0,
            fFixLeadTimeType: "",
            fIncreaseQty: 0,
            fIncreaseQtyUnit: "",
            fIsMrpComBill: "",
            fIsMrpComReq: "",
            fLeadExtendDay: 0,
            fMaxPoqty: 0,
            fMfgPolicyId: "",
            fMinPoqty: 0,
            fMinPoqtyUnit: "",
            fOrderIntervalTime: 0,
            fOrderIntervalTimeType: "",
            fOrderPolicy: "",
            fPlanBatchSplitQty: "",
            fPlanBatchSplitQtyUnit: "",
            fPlanGroupId: "",
            fPlanIdent: "",
            fPlanIntervalsDays: 0,
            fPlanOffsetTime: 0,
            fPlanOffsetTimeType: "",
            fPlanSafeStockQty: 0,
            fPlanSafeStockQtyUnit: "",
            fPlanTimeZone: 0,
            fPlanWorkshop: "",
            fPlanerId: "",
            fPlanningStrategy: "",
            fProScheTrackId: "",
            fProductLine: "",
            fRequestTimeZone: 0,
            fSupplySourceId: "",
            fVarLeadTime: 0,
            fVarLeadTimeLotSize: "",
            fVarLeadTimeLotSizeUnit: "",
            fVarLeadTimeType: "",
            fWriteOffQty: "",
            fWriteOffQtyUnit: "",
            id: "",
            materialId: "",
            maxPoqtyUnit: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            searchValue: "",
            updateBy: "",
            updateTime: "",
          },
          materialProcureEntity: {
            agentProcure: "",
            barCodeRule: "",
            createBy: "",
            createTime: "",
            dayProduction: 0,
            dayProductionUnit: "",
            defaultSupplier: "",
            defunctProductionLine: "",
            expenseItem: "",
            id: "",
            isControl: "",
            isDayProduction: "",
            isMaterialReturn: "",
            isQuota: "",
            isReq: "",
            materialId: "",
            minPackNum: "",
            minSpiltNum: 0,
            outsourcePricingUnit: "",
            outsourceType: "",
            outsourceUnit: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            procureGroup: "",
            procureId: "",
            procurePricingUnit: "",
            procureType: "",
            procureUnit: "",
            quotaMode: "",
            remark: "",
            repeatPutNum: "",
            searchValue: "",
            takeOverDelay: 0,
            takeOverDown: "",
            takeOverLead: 0,
            takeOverUp: "",
            updateBy: "",
            updateTime: "",
          },
          materialProductEntity: {
            createBy: "",
            createTime: "",
            deptId: "",
            fBackFlushType: "",
            fConsumVolatility: "",
            fDefaultLineId: "",
            fDefaultRouting: "",
            fFinishReceiptOverRate: "",
            fFinishReceiptShortRate: "",
            fIsCompleteSet: "",
            fIsEnableSchedule: "",
            fIsKitting: "",
            fIsMainPrd: "",
            fIsMinissueQty: "",
            fIsProductLine: "",
            fIsSNCarryToParent: "",
            fIssueType: "",
            fMdlId: "",
            fMdlMaterialId: "",
            fMinissueQty: 0,
            fMinissueUnitId: "",
            fOrgTrustBillType: "",
            fOverControlMode: "",
            fPerUnitStandHour: "",
            fPickBinId: "",
            fPickStockId: "",
            fProduceBillType: "",
            fProduceUnitId: "",
            fStandHourUnitId: "",
            fStdLaborPrePareTime: "",
            fStdLaborProcessTime: "",
            fStdMachinePrepareTime: "",
            fStdMachineProcessTime: "",
            fWorkShopId: "",
            fbkfltime: "",
            fbomunitid: "",
            ffixloss: "",
            fisecn: "",
            flosspercent: "",
            id: "",
            materialId: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            searchValue: "",
            updateBy: "",
            updateTime: "",
          },
          materialProperty: "",
          materialQualityEntity: {
            createBy: "",
            createTime: "",
            fCheckDelivery: "",
            fCheckEntrusted: "",
            fCheckIncoming: "",
            fCheckOther: "",
            fCheckProduct: "",
            fCheckReturn: "",
            fCheckStock: "",
            fCheckSubFtnMtrl: "",
            fEWLeadDay: "",
            fEnableCyclistQCSTK: "",
            fEnableCyclistQcstkew: "",
            fFirstQCControlType: "",
            fIncQcSchemeId: "",
            fIncSampSchemeId: "",
            fInspectGroupId: "",
            fInspectorId: "",
            fIsFirstInspect: "",
            fStockCycle: "",
            id: "",
            materialId: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            searchValue: "",
            updateBy: "",
            updateTime: "",
          },
          materialSaleEntity: {
            allowReleaseOrder: "",
            allowReturns: "",
            atpCheck: "",
            controlSurpassUnit: "",
            createBy: "",
            createTime: "",
            dropOutCount: "",
            fisReturnPart: "",
            fisaftersale: "",
            fisproductfiles: "",
            fiswarranted: "",
            fwarranty: "",
            fwarrantyunitid: "",
            id: "",
            isFavourableTax: "",
            materialId: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            saleDownPrice: "",
            saleGroup: "",
            saleOutbound: "",
            salePricingUnit: "",
            saleUnit: "",
            searchValue: "",
            startOrderNum: 0,
            surpassDown: "",
            surpassUp: "",
            taxType: "",
            taxTypeCode: "",
            updateBy: "",
            updateTime: "",
          },
          mnemonicCode: "",
          model: "",
          modelId: "",
          netWeight: "",
          oldMaterialCode: "",
          pageNo: 0,
          pageSize: 0,
          params: {},
          reasonForDisable: "",
          remark: "",
          searchValue: "",
          sizeUnit: "",
          state: "",
          subItems: "",
          taxType: "",
          typeName: "",
          unit: "",
          updateBy: "",
          updateTime: "",
          volume: "",
          weightUnit: "",
          wideStr: "",
        },
        materialCode: "",
        materialId: "",
        netAmount: "",
        noTaxMoney: "",
        number: 0,
        orderDelivery: {
          batchNum: "",
          bomVer: "",
          changeTime: "",
          controlDeliveryNum: true,
          controlDeliveryTime: true,
          createTime: "",
          deliveryDelayDay: "",
          deliveryDown: "",
          deliveryEarlyTime: "",
          deliveryLatestTime: "",
          deliveryLeadDay: "",
          deliveryUp: "",
          id: "",

          materialId: "",
          materialName: "",
          orderDeliveryDetails: [
            {
              address: "",
              changeTime: "",
              confirmComment: "",
              confirmNum: "",
              confirmTime: "",
              createTime: "",
              deliveredNum: "",
              deliveryTime: "",
              id: "",

              location: "",
              num: "",
              orderDeliveryId: "",
              orderId: "",
              planUnit: "",
              surplusNum: "",
              userId: "",
            },
          ],
          orderId: "",
          receiveDept: "",
          receiveOrg: "",
          requireDept: "",
          requireOrg: "",
          supplierBatch: "",
          supportAttr: "",
          userId: "",
        },
        orderFinanceDetail: {
          changeTime: "",
          createTime: "",
          discountAmount: "",
          discountRate: "",
          entryPriceInfo: "",
          id: "",

          materialCode: "",
          materialId: "",
          materialName: "",
          netPrice: "",
          orderId: "",
          priceCeiling: "",
          priceCoefficient: "",
          priceFloor: "",
          pricingNum: "",
          pricingUnit: "",
          settlementDept: "",
          systemPricing: "",
          taxRate: "",
          unitPriceDiscount: "",
          userId: "",
        },
        orderOther: {
          businessClose: "",
          businessFreeze: "",
          businessProcess: "",
          businessStop: "",
          changeTime: "",
          contractsCode: "",
          createTime: "",
          freezeName: "",
          freezeTime: "",
          id: "",
          inventoryReturnNum: "",
          isPlanConfirm: "",
          isQuotaGeneration: "",

          materialCode: "",
          materialId: "",
          materialName: "",
          materialReceivedReturnNum: "",
          orderId: "",
          planTrackingCode: "",
          requireDocCode: "",
          requireDocLineCode: "",
          requireFrom: "",
          requireTrackingCode: "",
          sourceDocCode: "",
          sourceDocType: "",
          stopName: "",
          stopTime: "",
          surplusInboundNum: "",
          surplusMaterialReceivedNum: "",
          totalInboundNum: "",
          totalMaterialReceivedNum: "",
          totalMaterialReturnNum: "",
          updateFlag: "",
          userId: "",
        },
        originalContainsTaxPrice: "",
        originalNumber: "",
        page: 0,
        parentMaterial: "",
        price: "",
        pricingNum: "",
        pricingUnit: "",
        purchaseUnit: "",
        ramarks: "",
        receivedFirstTicketsNum: "",
        receivingDept: "",
        relationId: "",
        requireDept: "",
        settlementDept: "",
        sourceDocCode: "",
        sourceDocType: "",
        sourceRelationId: "",
        supplierMaterialCode: "",
        supplierMaterialName: "",
        taxAmount: "",
        taxMoney: "",
        taxPrice: "",
        taxRate: "",
        token: "",
        totalAcceptanceAmount: "",
        totalAcceptanceRate: "",
        totalTaxPrice: "",
        type: 0,
        warehouseId: "",
        warehouseRegionId: "",
      };
      this.formObject.materialDetailEntities.push(materialObj);
      // this.open = false;
    },
    // 删除订单列表
    handleDataDelete(index, row, type) {
      this.$confirm("请确认是否要删除此行?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          if (type === "order") {
            this.formObject.orderEntities.splice(index, 1);
          } else {
            this.formObject.materialDetailEntities.splice(index, 1);
          }
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 新增行
    addNewRow(type) {
      if (type === "order") {
        this.handleDataAdd_order();
      } else {
        this.handleDataAdd_material();
      }
    },
    // 弹出弹窗
    showDialog(type, index) {
      this.open = true;
      this.loading = true;
      this.dialogType = type;
      const nameMap = {
        project: () => {
          this.dialogTitle = "项目列表";
          getProjectList().then((res) => {
            this.tableData = res.rows;
            this.total = res.total;
            this.loading = false;
          });
        },
        supplier: () => {
          this.dialogTitle = "供应商列表";
          getSupplyList().then((res) => {
            this.tableData = res.rows;
            this.total = res.total;
            this.loading = false;
          });
        },
        order: () => {
          this.getOrderLists();
        },
        material: () => {
          this.getMaterialLists(index);
        },
        pay: () => {
          this.dialogTitle = "付款方式列表";
          getPayType().then((res) => {
            this.tableData = res.rows;
            this.total = res.total;
            this.loading = false;
          });
        },
        rateType: () => {
          let params = {
            page: this.page,
            limit: this.limit,
          };
          getExchangeTypeData(params).then((res) => {
            this.tableData = res.rows;
            this.total = res.total;
          });
        },
        deptId: () => {
          let params = {
            limit: this.limit,
            page: this.page,
            level: this.deptLevel,
          };
          listDept(params).then((res) => {
            this.tableData = res.data;
            this.total = res.total;
          });
        },
      };
      nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
    },
    // 弹窗勾选项目
    selectProjectItem(val) {
      this.selectItem = val;
      if (this.dialogType == "deptId") {
        this.formObject.contractProcureEntity.deptId = this.selectItem.deptId;
        this.formObject.contractProcureEntity.deptName =
          this.selectItem.deptName;
        this.open = false;
      } else if (this.dialogType == "rateType") {
        this.formObject.contractProcureEntity.rateType = this.selectItem.id;
        this.formObject.contractProcureEntity.rateTypeCode =
          this.selectItem.code;
        this.formObject.contractProcureEntity.rateTypeName =
          this.selectItem.name;
        this.open = false;
      }
    },
    //弹窗勾选供应商
    selectSupplyItem(val) {
      this.selectItem = val;
    },
    // 获取订单
    getOrderLists() {
      this.dialogTitle = "选择订单物料";
      let limit = 10;
      let page = 1;
      getOrderList({ limit, page }).then((res) => {
        if (res.code === 200) {
          this.loading = false;
          this.tableData = res.data.records;
          this.total = res.data.total;
        }
      });
    },
    // 弹窗勾选订单
    selectOrdertem(val) {
      this.selectItem = val;
    },
    // 弹框确认按钮
    confirmSelect() {
      const nameMap = {
        project: () => {
          if (this.selectItem.length !== 1) {
            this.$message.error("请选择一条记录！");
            return;
          }
          this.formObject.contractProcureEntity.projectId =
            this.selectItem[0].id;
          this.formObject.contractProcureEntity.projectName =
            this.selectItem[0].deptName;
          this.open = false;
        },
        supplier: () => {
          if (this.selectItem.length !== 1) {
            this.$message.error("请选择一条记录！");
            return;
          }
          this.formObject.contractProcureEntity.supplierId =
            this.selectItem[0].id;
          this.formObject.contractProcureEntity.supplierName =
            this.selectItem[0].supplierName;
          this.open = false;
        },
        order: () => {
          this.handleOrder();
        },
        material: () => {
          this.handleMaterial();
        },
        pay: () => {
          if (this.selectItem.length !== 1) {
            this.$message.error("请选择一条记录！");
            return;
          }
          this.formObject.contractProcureEntity.payType = this.selectItem[0].id;
          this.formObject.contractProcureEntity.payTypeName =
            this.selectItem[0].typeName;
          this.open = false;
        },
      };
      nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
    },
    // 物料回显
    handleMaterial() {
      if (this.currentIndex < 0) {
        // 导入物料按钮
        this.selectItem.forEach((item) => {
          let materialObj = {
            amountMoney: "",
            batchNum: "",
            businessTaxCostPrice: "",
            changeTime: "",
            changeType: "",
            containsTaxPrice: "",
            createTime: "",
            deliveryAddress: "",
            deliveryDate: "",
            deliveryLocation: "",
            discountAmount: "",
            discountRate: "",
            executeStatus: "",
            id: "",
            sourceMaterialDetailId: "",
            inventoryId: "",
            inventoryNum: 0,
            inventoryUnit: "",
            isGiveaway: true,

            limit: 0,
            material: {
              allowAsset: "",
              allowInventory: "",
              allowOutsource: "",
              allowProduce: "",
              allowPurchase: "",
              allowSale: "",
              barCode: "",
              brand: "",
              businessType: "",
              configurationProduction: "",
              costPriceRatio: "",
              createBy: "",
              createTime: "",
              dataState: "",
              defaultTaxRate: "",
              deptId: "",
              disableBy: "",
              examineBy: "",
              examineTime: "",
              grossWeight: "",
              heightStr: "",
              id: "",
              imgUrl: "",
              instanceId: "",
              inventoryType: "",
              isChange: "",

              kit: "",
              lengthStr: "",
              materialCode: "",
              materialDesc: "",
              materialGroup: "",
              materialInventoryEntity: {
                batchInfo: "",
                batchRule: "",
                checkCycle: "",
                convertDirection: "",
                costUnit: "",
                createBy: "",
                createTime: "",
                currency: "",
                day: "",
                economicOrderingBatch: "",
                id: "",
                inventoryUnit: "",
                isBatch: "",
                isCheck: "",
                isLock: "",
                isMaxInventory: "",
                isMinInventory: "",
                isOrderGoods: "",
                isSafeInventory: "",
                isTrueCheck: "",
                materialId: "",
                maxInventoyNum: "",
                minInventoryNum: "",
                orderGoodsNum: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                qualityManage: "",
                qualityNum: "",
                qualityUnit: "",
                referenceCost: "",
                remark: "",
                safeInventoryNum: "",
                searchValue: "",
                serviceLife: "",
                standardNumber: "",
                supportUnit: "",
                updateBy: "",
                updateTime: "",
                warePosition: "",
                warehouseCode: "",
              },
              materialName: "",
              materialPlanAttributeEntity: {
                createBy: "",
                createTime: "",
                fAllowPartDelay: "",
                fBaseVarLeadTimeLotSize: "",
                fBaseVarLeadTimeLotSizeUnit: "",
                fCanDelayDays: 0,
                fCanLeadDays: 0,
                fCheckLeadTime: 0,
                fCheckLeadTimeType: "",
                fDelayExtendDay: 0,
                fFixLeadTime: 0,
                fFixLeadTimeType: "",
                fIncreaseQty: 0,
                fIncreaseQtyUnit: "",
                fIsMrpComBill: "",
                fIsMrpComReq: "",
                fLeadExtendDay: 0,
                fMaxPoqty: 0,
                fMfgPolicyId: "",
                fMinPoqty: 0,
                fMinPoqtyUnit: "",
                fOrderIntervalTime: 0,
                fOrderIntervalTimeType: "",
                fOrderPolicy: "",
                fPlanBatchSplitQty: "",
                fPlanBatchSplitQtyUnit: "",
                fPlanGroupId: "",
                fPlanIdent: "",
                fPlanIntervalsDays: 0,
                fPlanOffsetTime: 0,
                fPlanOffsetTimeType: "",
                fPlanSafeStockQty: 0,
                fPlanSafeStockQtyUnit: "",
                fPlanTimeZone: 0,
                fPlanWorkshop: "",
                fPlanerId: "",
                fPlanningStrategy: "",
                fProScheTrackId: "",
                fProductLine: "",
                fRequestTimeZone: 0,
                fSupplySourceId: "",
                fVarLeadTime: 0,
                fVarLeadTimeLotSize: "",
                fVarLeadTimeLotSizeUnit: "",
                fVarLeadTimeType: "",
                fWriteOffQty: "",
                fWriteOffQtyUnit: "",
                id: "",
                materialId: "",
                maxPoqtyUnit: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                searchValue: "",
                updateBy: "",
                updateTime: "",
              },
              materialProcureEntity: {
                agentProcure: "",
                barCodeRule: "",
                createBy: "",
                createTime: "",
                dayProduction: 0,
                dayProductionUnit: "",
                defaultSupplier: "",
                defunctProductionLine: "",
                expenseItem: "",
                id: "",
                isControl: "",
                isDayProduction: "",
                isMaterialReturn: "",
                isQuota: "",
                isReq: "",
                materialId: "",
                minPackNum: "",
                minSpiltNum: 0,
                outsourcePricingUnit: "",
                outsourceType: "",
                outsourceUnit: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                procureGroup: "",
                procureId: "",
                procurePricingUnit: "",
                procureType: "",
                procureUnit: "",
                quotaMode: "",
                remark: "",
                repeatPutNum: "",
                searchValue: "",
                takeOverDelay: 0,
                takeOverDown: "",
                takeOverLead: 0,
                takeOverUp: "",
                updateBy: "",
                updateTime: "",
              },
              materialProductEntity: {
                createBy: "",
                createTime: "",
                deptId: "",
                fBackFlushType: "",
                fConsumVolatility: "",
                fDefaultLineId: "",
                fDefaultRouting: "",
                fFinishReceiptOverRate: "",
                fFinishReceiptShortRate: "",
                fIsCompleteSet: "",
                fIsEnableSchedule: "",
                fIsKitting: "",
                fIsMainPrd: "",
                fIsMinissueQty: "",
                fIsProductLine: "",
                fIsSNCarryToParent: "",
                fIssueType: "",
                fMdlId: "",
                fMdlMaterialId: "",
                fMinissueQty: 0,
                fMinissueUnitId: "",
                fOrgTrustBillType: "",
                fOverControlMode: "",
                fPerUnitStandHour: "",
                fPickBinId: "",
                fPickStockId: "",
                fProduceBillType: "",
                fProduceUnitId: "",
                fStandHourUnitId: "",
                fStdLaborPrePareTime: "",
                fStdLaborProcessTime: "",
                fStdMachinePrepareTime: "",
                fStdMachineProcessTime: "",
                fWorkShopId: "",
                fbkfltime: "",
                fbomunitid: "",
                ffixloss: "",
                fisecn: "",
                flosspercent: "",
                id: "",
                materialId: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                searchValue: "",
                updateBy: "",
                updateTime: "",
              },
              materialProperty: "",
              materialQualityEntity: {
                createBy: "",
                createTime: "",
                fCheckDelivery: "",
                fCheckEntrusted: "",
                fCheckIncoming: "",
                fCheckOther: "",
                fCheckProduct: "",
                fCheckReturn: "",
                fCheckStock: "",
                fCheckSubFtnMtrl: "",
                fEWLeadDay: "",
                fEnableCyclistQCSTK: "",
                fEnableCyclistQcstkew: "",
                fFirstQCControlType: "",
                fIncQcSchemeId: "",
                fIncSampSchemeId: "",
                fInspectGroupId: "",
                fInspectorId: "",
                fIsFirstInspect: "",
                fStockCycle: "",
                id: "",
                materialId: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                searchValue: "",
                updateBy: "",
                updateTime: "",
              },
              materialSaleEntity: {
                allowReleaseOrder: "",
                allowReturns: "",
                atpCheck: "",
                controlSurpassUnit: "",
                createBy: "",
                createTime: "",
                dropOutCount: "",
                fisReturnPart: "",
                fisaftersale: "",
                fisproductfiles: "",
                fiswarranted: "",
                fwarranty: "",
                fwarrantyunitid: "",
                id: "",
                isFavourableTax: "",
                materialId: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                saleDownPrice: "",
                saleGroup: "",
                saleOutbound: "",
                salePricingUnit: "",
                saleUnit: "",
                searchValue: "",
                startOrderNum: 0,
                surpassDown: "",
                surpassUp: "",
                taxType: "",
                taxTypeCode: "",
                updateBy: "",
                updateTime: "",
              },
              mnemonicCode: "",
              model: "",
              modelId: "",
              netWeight: "",
              oldMaterialCode: "",
              pageNo: 0,
              pageSize: 0,
              params: {},
              reasonForDisable: "",
              remark: "",
              searchValue: "",
              sizeUnit: "",
              state: "",
              subItems: "",
              taxType: "",
              typeName: "",
              unit: "",
              updateBy: "",
              updateTime: "",
              volume: "",
              weightUnit: "",
              wideStr: "",
            },
            materialCode: "",
            materialName: "",
            materialId: "",
            netAmount: "",
            noTaxMoney: "",
            number: 0,
            orderDelivery: {
              batchNum: "",
              bomVer: "",
              changeTime: "",
              controlDeliveryNum: true,
              controlDeliveryTime: true,
              createTime: "",
              deliveryDelayDay: "",
              deliveryDown: "",
              deliveryEarlyTime: "",
              deliveryLatestTime: "",
              deliveryLeadDay: "",
              deliveryUp: "",
              id: "",

              materialId: "",
              materialName: "",
              orderDeliveryDetails: [
                {
                  address: "",
                  changeTime: "",
                  confirmComment: "",
                  confirmNum: "",
                  confirmTime: "",
                  createTime: "",
                  deliveredNum: "",
                  deliveryTime: "",
                  id: "",

                  location: "",
                  num: "",
                  orderDeliveryId: "",
                  orderId: "",
                  planUnit: "",
                  surplusNum: "",
                  userId: "",
                },
              ],
              orderId: "",
              receiveDept: "",
              receiveOrg: "",
              requireDept: "",
              requireOrg: "",
              supplierBatch: "",
              supportAttr: "",
              userId: "",
            },
            orderFinanceDetail: {
              changeTime: "",
              createTime: "",
              discountAmount: "",
              discountRate: "",
              entryPriceInfo: "",
              id: "",

              materialCode: "",
              materialId: "",
              materialName: "",
              netPrice: "",
              orderId: "",
              priceCeiling: "",
              priceCoefficient: "",
              priceFloor: "",
              pricingNum: "",
              pricingUnit: "",
              settlementDept: "",
              systemPricing: "",
              taxRate: "",
              unitPriceDiscount: "",
              userId: "",
            },
            orderOther: {
              businessClose: "",
              businessFreeze: "",
              businessProcess: "",
              businessStop: "",
              changeTime: "",
              contractsCode: "",
              createTime: "",
              freezeName: "",
              freezeTime: "",
              id: "",
              inventoryReturnNum: "",
              isPlanConfirm: "",
              isQuotaGeneration: "",

              materialCode: "",
              materialId: "",
              materialName: "",
              materialReceivedReturnNum: "",
              orderId: "",
              planTrackingCode: "",
              requireDocCode: "",
              requireDocLineCode: "",
              requireFrom: "",
              requireTrackingCode: "",
              sourceDocCode: "",
              sourceDocType: "",
              stopName: "",
              stopTime: "",
              surplusInboundNum: "",
              surplusMaterialReceivedNum: "",
              totalInboundNum: "",
              totalMaterialReceivedNum: "",
              totalMaterialReturnNum: "",
              updateFlag: "",
              userId: "",
            },
            originalContainsTaxPrice: "",
            originalNumber: "",
            page: 0,
            parentMaterial: "",
            price: "",
            pricingNum: "",
            pricingUnit: "",
            purchaseUnit: "",
            ramarks: "",
            receivedFirstTicketsNum: "",
            receivingDept: "",
            relationId: "",
            requireDept: "",
            settlementDept: "",
            sourceDocCode: "",
            sourceDocType: "",
            sourceRelationId: "",
            supplierMaterialCode: "",
            supplierMaterialName: "",
            taxAmount: "",
            taxMoney: "",
            taxPrice: "",
            taxRate: "",
            token: "",
            totalAcceptanceAmount: "",
            totalAcceptanceRate: "",
            totalTaxPrice: "",
            type: 0,
            warehouseId: "",
            warehouseRegionId: "",
          };
          Object.keys(item).forEach((itemKey) => {
            Object.keys(materialObj).forEach((materialKey) => {
              if (itemKey === materialKey) {
                materialObj[materialKey] = item[itemKey];
              }
            });
          });
          this.formObject.materialDetailEntities.push(materialObj);
        });
      }
      if (this.currentIndex >= 0) {
        // 图标按钮
        // this.formObject.materialDetailEntities.splice(
        //     this.currentIndex,
        //     1
        // );
        this.selectItem.forEach((item) => {
          let materialObj = {
            amountMoney: "",
            batchNum: "",
            businessTaxCostPrice: "",
            changeTime: "",
            changeType: "",
            containsTaxPrice: "",
            createTime: "",
            deliveryAddress: "",
            deliveryDate: "",
            deliveryLocation: "",
            discountAmount: "",
            discountRate: "",
            executeStatus: "",
            id: "",
            sourceMaterialDetailId: "",
            inventoryId: "",
            inventoryNum: 0,
            inventoryUnit: "",
            isGiveaway: true,

            limit: 0,
            material: {
              allowAsset: "",
              allowInventory: "",
              allowOutsource: "",
              allowProduce: "",
              allowPurchase: "",
              allowSale: "",
              barCode: "",
              brand: "",
              businessType: "",
              configurationProduction: "",
              costPriceRatio: "",
              createBy: "",
              createTime: "",
              dataState: "",
              defaultTaxRate: "",
              deptId: "",
              disableBy: "",
              examineBy: "",
              examineTime: "",
              grossWeight: "",
              heightStr: "",
              id: "",
              imgUrl: "",
              instanceId: "",
              inventoryType: "",
              isChange: "",

              kit: "",
              lengthStr: "",
              materialCode: "",
              materialDesc: "",
              materialGroup: "",
              materialInventoryEntity: {
                batchInfo: "",
                batchRule: "",
                checkCycle: "",
                convertDirection: "",
                costUnit: "",
                createBy: "",
                createTime: "",
                currency: "",
                day: "",
                economicOrderingBatch: "",
                id: "",
                inventoryUnit: "",
                isBatch: "",
                isCheck: "",
                isLock: "",
                isMaxInventory: "",
                isMinInventory: "",
                isOrderGoods: "",
                isSafeInventory: "",
                isTrueCheck: "",
                materialId: "",
                maxInventoyNum: "",
                minInventoryNum: "",
                orderGoodsNum: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                qualityManage: "",
                qualityNum: "",
                qualityUnit: "",
                referenceCost: "",
                remark: "",
                safeInventoryNum: "",
                searchValue: "",
                serviceLife: "",
                standardNumber: "",
                supportUnit: "",
                updateBy: "",
                updateTime: "",
                warePosition: "",
                warehouseCode: "",
              },
              materialName: "",
              materialPlanAttributeEntity: {
                createBy: "",
                createTime: "",
                fAllowPartDelay: "",
                fBaseVarLeadTimeLotSize: "",
                fBaseVarLeadTimeLotSizeUnit: "",
                fCanDelayDays: 0,
                fCanLeadDays: 0,
                fCheckLeadTime: 0,
                fCheckLeadTimeType: "",
                fDelayExtendDay: 0,
                fFixLeadTime: 0,
                fFixLeadTimeType: "",
                fIncreaseQty: 0,
                fIncreaseQtyUnit: "",
                fIsMrpComBill: "",
                fIsMrpComReq: "",
                fLeadExtendDay: 0,
                fMaxPoqty: 0,
                fMfgPolicyId: "",
                fMinPoqty: 0,
                fMinPoqtyUnit: "",
                fOrderIntervalTime: 0,
                fOrderIntervalTimeType: "",
                fOrderPolicy: "",
                fPlanBatchSplitQty: "",
                fPlanBatchSplitQtyUnit: "",
                fPlanGroupId: "",
                fPlanIdent: "",
                fPlanIntervalsDays: 0,
                fPlanOffsetTime: 0,
                fPlanOffsetTimeType: "",
                fPlanSafeStockQty: 0,
                fPlanSafeStockQtyUnit: "",
                fPlanTimeZone: 0,
                fPlanWorkshop: "",
                fPlanerId: "",
                fPlanningStrategy: "",
                fProScheTrackId: "",
                fProductLine: "",
                fRequestTimeZone: 0,
                fSupplySourceId: "",
                fVarLeadTime: 0,
                fVarLeadTimeLotSize: "",
                fVarLeadTimeLotSizeUnit: "",
                fVarLeadTimeType: "",
                fWriteOffQty: "",
                fWriteOffQtyUnit: "",
                id: "",
                materialId: "",
                maxPoqtyUnit: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                searchValue: "",
                updateBy: "",
                updateTime: "",
              },
              materialProcureEntity: {
                agentProcure: "",
                barCodeRule: "",
                createBy: "",
                createTime: "",
                dayProduction: 0,
                dayProductionUnit: "",
                defaultSupplier: "",
                defunctProductionLine: "",
                expenseItem: "",
                id: "",
                isControl: "",
                isDayProduction: "",
                isMaterialReturn: "",
                isQuota: "",
                isReq: "",
                materialId: "",
                minPackNum: "",
                minSpiltNum: 0,
                outsourcePricingUnit: "",
                outsourceType: "",
                outsourceUnit: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                procureGroup: "",
                procureId: "",
                procurePricingUnit: "",
                procureType: "",
                procureUnit: "",
                quotaMode: "",
                remark: "",
                repeatPutNum: "",
                searchValue: "",
                takeOverDelay: 0,
                takeOverDown: "",
                takeOverLead: 0,
                takeOverUp: "",
                updateBy: "",
                updateTime: "",
              },
              materialProductEntity: {
                createBy: "",
                createTime: "",
                deptId: "",
                fBackFlushType: "",
                fConsumVolatility: "",
                fDefaultLineId: "",
                fDefaultRouting: "",
                fFinishReceiptOverRate: "",
                fFinishReceiptShortRate: "",
                fIsCompleteSet: "",
                fIsEnableSchedule: "",
                fIsKitting: "",
                fIsMainPrd: "",
                fIsMinissueQty: "",
                fIsProductLine: "",
                fIsSNCarryToParent: "",
                fIssueType: "",
                fMdlId: "",
                fMdlMaterialId: "",
                fMinissueQty: 0,
                fMinissueUnitId: "",
                fOrgTrustBillType: "",
                fOverControlMode: "",
                fPerUnitStandHour: "",
                fPickBinId: "",
                fPickStockId: "",
                fProduceBillType: "",
                fProduceUnitId: "",
                fStandHourUnitId: "",
                fStdLaborPrePareTime: "",
                fStdLaborProcessTime: "",
                fStdMachinePrepareTime: "",
                fStdMachineProcessTime: "",
                fWorkShopId: "",
                fbkfltime: "",
                fbomunitid: "",
                ffixloss: "",
                fisecn: "",
                flosspercent: "",
                id: "",
                materialId: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                searchValue: "",
                updateBy: "",
                updateTime: "",
              },
              materialProperty: "",
              materialQualityEntity: {
                createBy: "",
                createTime: "",
                fCheckDelivery: "",
                fCheckEntrusted: "",
                fCheckIncoming: "",
                fCheckOther: "",
                fCheckProduct: "",
                fCheckReturn: "",
                fCheckStock: "",
                fCheckSubFtnMtrl: "",
                fEWLeadDay: "",
                fEnableCyclistQCSTK: "",
                fEnableCyclistQcstkew: "",
                fFirstQCControlType: "",
                fIncQcSchemeId: "",
                fIncSampSchemeId: "",
                fInspectGroupId: "",
                fInspectorId: "",
                fIsFirstInspect: "",
                fStockCycle: "",
                id: "",
                materialId: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                searchValue: "",
                updateBy: "",
                updateTime: "",
              },
              materialSaleEntity: {
                allowReleaseOrder: "",
                allowReturns: "",
                atpCheck: "",
                controlSurpassUnit: "",
                createBy: "",
                createTime: "",
                dropOutCount: "",
                fisReturnPart: "",
                fisaftersale: "",
                fisproductfiles: "",
                fiswarranted: "",
                fwarranty: "",
                fwarrantyunitid: "",
                id: "",
                isFavourableTax: "",
                materialId: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                saleDownPrice: "",
                saleGroup: "",
                saleOutbound: "",
                salePricingUnit: "",
                saleUnit: "",
                searchValue: "",
                startOrderNum: 0,
                surpassDown: "",
                surpassUp: "",
                taxType: "",
                taxTypeCode: "",
                updateBy: "",
                updateTime: "",
              },
              mnemonicCode: "",
              model: "",
              modelId: "",
              netWeight: "",
              oldMaterialCode: "",
              pageNo: 0,
              pageSize: 0,
              params: {},
              reasonForDisable: "",
              remark: "",
              searchValue: "",
              sizeUnit: "",
              state: "",
              subItems: "",
              taxType: "",
              typeName: "",
              unit: "",
              updateBy: "",
              updateTime: "",
              volume: "",
              weightUnit: "",
              wideStr: "",
            },
            materialCode: "",
            materialName: "",
            materialId: "",
            netAmount: "",
            noTaxMoney: "",
            number: 0,
            orderDelivery: {
              batchNum: "",
              bomVer: "",
              changeTime: "",
              controlDeliveryNum: true,
              controlDeliveryTime: true,
              createTime: "",
              deliveryDelayDay: "",
              deliveryDown: "",
              deliveryEarlyTime: "",
              deliveryLatestTime: "",
              deliveryLeadDay: "",
              deliveryUp: "",
              id: "",

              materialId: "",
              materialName: "",
              orderDeliveryDetails: [
                {
                  address: "",
                  changeTime: "",
                  confirmComment: "",
                  confirmNum: "",
                  confirmTime: "",
                  createTime: "",
                  deliveredNum: "",
                  deliveryTime: "",
                  id: "",

                  location: "",
                  num: "",
                  orderDeliveryId: "",
                  orderId: "",
                  planUnit: "",
                  surplusNum: "",
                  userId: "",
                },
              ],
              orderId: "",
              receiveDept: "",
              receiveOrg: "",
              requireDept: "",
              requireOrg: "",
              supplierBatch: "",
              supportAttr: "",
              userId: "",
            },
            orderFinanceDetail: {
              changeTime: "",
              createTime: "",
              discountAmount: "",
              discountRate: "",
              entryPriceInfo: "",
              id: "",

              materialCode: "",
              materialId: "",
              materialName: "",
              netPrice: "",
              orderId: "",
              priceCeiling: "",
              priceCoefficient: "",
              priceFloor: "",
              pricingNum: "",
              pricingUnit: "",
              settlementDept: "",
              systemPricing: "",
              taxRate: "",
              unitPriceDiscount: "",
              userId: "",
            },
            orderOther: {
              businessClose: "",
              businessFreeze: "",
              businessProcess: "",
              businessStop: "",
              changeTime: "",
              contractsCode: "",
              createTime: "",
              freezeName: "",
              freezeTime: "",
              id: "",
              inventoryReturnNum: "",
              isPlanConfirm: "",
              isQuotaGeneration: "",

              materialCode: "",
              materialId: "",
              materialName: "",
              materialReceivedReturnNum: "",
              orderId: "",
              planTrackingCode: "",
              requireDocCode: "",
              requireDocLineCode: "",
              requireFrom: "",
              requireTrackingCode: "",
              sourceDocCode: "",
              sourceDocType: "",
              stopName: "",
              stopTime: "",
              surplusInboundNum: "",
              surplusMaterialReceivedNum: "",
              totalInboundNum: "",
              totalMaterialReceivedNum: "",
              totalMaterialReturnNum: "",
              updateFlag: "",
              userId: "",
            },
            originalContainsTaxPrice: "",
            originalNumber: "",
            page: 0,
            parentMaterial: "",
            price: "",
            pricingNum: "",
            pricingUnit: "",
            purchaseUnit: "",
            ramarks: "",
            receivedFirstTicketsNum: "",
            receivingDept: "",
            relationId: "",
            requireDept: "",
            settlementDept: "",
            sourceDocCode: "",
            sourceDocType: "",
            sourceRelationId: "",
            supplierMaterialCode: "",
            supplierMaterialName: "",
            taxAmount: "",
            taxMoney: "",
            taxPrice: "",
            taxRate: "",
            token: "",
            totalAcceptanceAmount: "",
            totalAcceptanceRate: "",
            totalTaxPrice: "",
            type: 0,
            warehouseId: "",
            warehouseRegionId: "",
          };
          Object.keys(item).forEach((itemKey) => {
            Object.keys(materialObj).forEach((materialKey) => {
              if (itemKey === materialKey) {
                materialObj[materialKey] = item[itemKey];
              }
              if (itemKey === "id") {
                materialObj["id"] = "";
              }
            });
          });
          this.$set(
            this.formObject.materialDetailEntities,
            this.currentIndex,
            materialObj
          );
          // this.formObject.materialDetailEntities.push(materialObj);
        });
      }
      this.open = false;
    },
    // 选单回显
    handleOrder() {
      if (this.selectItem.length === 0) {
        this.$message.error("请选择一条记录！");
        return;
      }
      if (this.selectItem.length >= 1) {
        let flag = this.selectItem.every((item) => {
          return item.supplierId === this.selectItem[0].supplierId;
        });
        if (!flag) {
          this.$message.error("请选择相同供应商的订单！");
          return;
        }
        this.selectItem.forEach((item) => {
          let materialObj = {
            amountMoney: "",
            batchNum: "",
            businessTaxCostPrice: "",
            changeTime: "",
            changeType: "",
            containsTaxPrice: "",
            createTime: "",
            deliveryAddress: "",
            deliveryDate: "",
            deliveryLocation: "",
            discountAmount: "",
            discountRate: "",
            executeStatus: "",
            id: "",
            sourceMaterialDetailId: "",
            inventoryId: "",
            inventoryNum: 0,
            inventoryUnit: "",
            isGiveaway: true,

            limit: 0,
            material: {
              allowAsset: "",
              allowInventory: "",
              allowOutsource: "",
              allowProduce: "",
              allowPurchase: "",
              allowSale: "",
              barCode: "",
              brand: "",
              businessType: "",
              configurationProduction: "",
              costPriceRatio: "",
              createBy: "",
              createTime: "",
              dataState: "",
              defaultTaxRate: "",
              deptId: "",
              disableBy: "",
              examineBy: "",
              examineTime: "",
              grossWeight: "",
              heightStr: "",
              id: "",
              imgUrl: "",
              instanceId: "",
              inventoryType: "",
              isChange: "",

              kit: "",
              lengthStr: "",
              materialCode: "",
              materialDesc: "",
              materialGroup: "",
              materialInventoryEntity: {
                batchInfo: "",
                batchRule: "",
                checkCycle: "",
                convertDirection: "",
                costUnit: "",
                createBy: "",
                createTime: "",
                currency: "",
                day: "",
                economicOrderingBatch: "",
                id: "",
                inventoryUnit: "",
                isBatch: "",
                isCheck: "",
                isLock: "",
                isMaxInventory: "",
                isMinInventory: "",
                isOrderGoods: "",
                isSafeInventory: "",
                isTrueCheck: "",
                materialId: "",
                maxInventoyNum: "",
                minInventoryNum: "",
                orderGoodsNum: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                qualityManage: "",
                qualityNum: "",
                qualityUnit: "",
                referenceCost: "",
                remark: "",
                safeInventoryNum: "",
                searchValue: "",
                serviceLife: "",
                standardNumber: "",
                supportUnit: "",
                updateBy: "",
                updateTime: "",
                warePosition: "",
                warehouseCode: "",
              },
              materialName: "",
              materialPlanAttributeEntity: {
                createBy: "",
                createTime: "",
                fAllowPartDelay: "",
                fBaseVarLeadTimeLotSize: "",
                fBaseVarLeadTimeLotSizeUnit: "",
                fCanDelayDays: 0,
                fCanLeadDays: 0,
                fCheckLeadTime: 0,
                fCheckLeadTimeType: "",
                fDelayExtendDay: 0,
                fFixLeadTime: 0,
                fFixLeadTimeType: "",
                fIncreaseQty: 0,
                fIncreaseQtyUnit: "",
                fIsMrpComBill: "",
                fIsMrpComReq: "",
                fLeadExtendDay: 0,
                fMaxPoqty: 0,
                fMfgPolicyId: "",
                fMinPoqty: 0,
                fMinPoqtyUnit: "",
                fOrderIntervalTime: 0,
                fOrderIntervalTimeType: "",
                fOrderPolicy: "",
                fPlanBatchSplitQty: "",
                fPlanBatchSplitQtyUnit: "",
                fPlanGroupId: "",
                fPlanIdent: "",
                fPlanIntervalsDays: 0,
                fPlanOffsetTime: 0,
                fPlanOffsetTimeType: "",
                fPlanSafeStockQty: 0,
                fPlanSafeStockQtyUnit: "",
                fPlanTimeZone: 0,
                fPlanWorkshop: "",
                fPlanerId: "",
                fPlanningStrategy: "",
                fProScheTrackId: "",
                fProductLine: "",
                fRequestTimeZone: 0,
                fSupplySourceId: "",
                fVarLeadTime: 0,
                fVarLeadTimeLotSize: "",
                fVarLeadTimeLotSizeUnit: "",
                fVarLeadTimeType: "",
                fWriteOffQty: "",
                fWriteOffQtyUnit: "",
                id: "",
                materialId: "",
                maxPoqtyUnit: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                searchValue: "",
                updateBy: "",
                updateTime: "",
              },
              materialProcureEntity: {
                agentProcure: "",
                barCodeRule: "",
                createBy: "",
                createTime: "",
                dayProduction: 0,
                dayProductionUnit: "",
                defaultSupplier: "",
                defunctProductionLine: "",
                expenseItem: "",
                id: "",
                isControl: "",
                isDayProduction: "",
                isMaterialReturn: "",
                isQuota: "",
                isReq: "",
                materialId: "",
                minPackNum: "",
                minSpiltNum: 0,
                outsourcePricingUnit: "",
                outsourceType: "",
                outsourceUnit: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                procureGroup: "",
                procureId: "",
                procurePricingUnit: "",
                procureType: "",
                procureUnit: "",
                quotaMode: "",
                remark: "",
                repeatPutNum: "",
                searchValue: "",
                takeOverDelay: 0,
                takeOverDown: "",
                takeOverLead: 0,
                takeOverUp: "",
                updateBy: "",
                updateTime: "",
              },
              materialProductEntity: {
                createBy: "",
                createTime: "",
                deptId: "",
                fBackFlushType: "",
                fConsumVolatility: "",
                fDefaultLineId: "",
                fDefaultRouting: "",
                fFinishReceiptOverRate: "",
                fFinishReceiptShortRate: "",
                fIsCompleteSet: "",
                fIsEnableSchedule: "",
                fIsKitting: "",
                fIsMainPrd: "",
                fIsMinissueQty: "",
                fIsProductLine: "",
                fIsSNCarryToParent: "",
                fIssueType: "",
                fMdlId: "",
                fMdlMaterialId: "",
                fMinissueQty: 0,
                fMinissueUnitId: "",
                fOrgTrustBillType: "",
                fOverControlMode: "",
                fPerUnitStandHour: "",
                fPickBinId: "",
                fPickStockId: "",
                fProduceBillType: "",
                fProduceUnitId: "",
                fStandHourUnitId: "",
                fStdLaborPrePareTime: "",
                fStdLaborProcessTime: "",
                fStdMachinePrepareTime: "",
                fStdMachineProcessTime: "",
                fWorkShopId: "",
                fbkfltime: "",
                fbomunitid: "",
                ffixloss: "",
                fisecn: "",
                flosspercent: "",
                id: "",
                materialId: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                searchValue: "",
                updateBy: "",
                updateTime: "",
              },
              materialProperty: "",
              materialQualityEntity: {
                createBy: "",
                createTime: "",
                fCheckDelivery: "",
                fCheckEntrusted: "",
                fCheckIncoming: "",
                fCheckOther: "",
                fCheckProduct: "",
                fCheckReturn: "",
                fCheckStock: "",
                fCheckSubFtnMtrl: "",
                fEWLeadDay: "",
                fEnableCyclistQCSTK: "",
                fEnableCyclistQcstkew: "",
                fFirstQCControlType: "",
                fIncQcSchemeId: "",
                fIncSampSchemeId: "",
                fInspectGroupId: "",
                fInspectorId: "",
                fIsFirstInspect: "",
                fStockCycle: "",
                id: "",
                materialId: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                searchValue: "",
                updateBy: "",
                updateTime: "",
              },
              materialSaleEntity: {
                allowReleaseOrder: "",
                allowReturns: "",
                atpCheck: "",
                controlSurpassUnit: "",
                createBy: "",
                createTime: "",
                dropOutCount: "",
                fisReturnPart: "",
                fisaftersale: "",
                fisproductfiles: "",
                fiswarranted: "",
                fwarranty: "",
                fwarrantyunitid: "",
                id: "",
                isFavourableTax: "",
                materialId: "",
                pageNo: 0,
                pageSize: 0,
                params: {},
                remark: "",
                saleDownPrice: "",
                saleGroup: "",
                saleOutbound: "",
                salePricingUnit: "",
                saleUnit: "",
                searchValue: "",
                startOrderNum: 0,
                surpassDown: "",
                surpassUp: "",
                taxType: "",
                taxTypeCode: "",
                updateBy: "",
                updateTime: "",
              },
              mnemonicCode: "",
              model: "",
              modelId: "",
              netWeight: "",
              oldMaterialCode: "",
              pageNo: 0,
              pageSize: 0,
              params: {},
              reasonForDisable: "",
              remark: "",
              searchValue: "",
              sizeUnit: "",
              state: "",
              subItems: "",
              taxType: "",
              typeName: "",
              unit: "",
              updateBy: "",
              updateTime: "",
              volume: "",
              weightUnit: "",
              wideStr: "",
            },
            materialCode: "",
            materialId: "",
            netAmount: "",
            noTaxMoney: "",
            number: 0,
            orderDelivery: {
              batchNum: "",
              bomVer: "",
              changeTime: "",
              controlDeliveryNum: true,
              controlDeliveryTime: true,
              createTime: "",
              deliveryDelayDay: "",
              deliveryDown: "",
              deliveryEarlyTime: "",
              deliveryLatestTime: "",
              deliveryLeadDay: "",
              deliveryUp: "",
              id: "",

              materialId: "",
              materialName: "",
              orderDeliveryDetails: [
                {
                  address: "",
                  changeTime: "",
                  confirmComment: "",
                  confirmNum: "",
                  confirmTime: "",
                  createTime: "",
                  deliveredNum: "",
                  deliveryTime: "",
                  id: "",

                  location: "",
                  num: "",
                  orderDeliveryId: "",
                  orderId: "",
                  planUnit: "",
                  surplusNum: "",
                  userId: "",
                },
              ],
              orderId: "",
              receiveDept: "",
              receiveOrg: "",
              requireDept: "",
              requireOrg: "",
              supplierBatch: "",
              supportAttr: "",
              userId: "",
            },
            orderFinanceDetail: {
              changeTime: "",
              createTime: "",
              discountAmount: "",
              discountRate: "",
              entryPriceInfo: "",
              id: "",

              materialCode: "",
              materialId: "",
              materialName: "",
              netPrice: "",
              orderId: "",
              priceCeiling: "",
              priceCoefficient: "",
              priceFloor: "",
              pricingNum: "",
              pricingUnit: "",
              settlementDept: "",
              systemPricing: "",
              taxRate: "",
              unitPriceDiscount: "",
              userId: "",
            },
            orderOther: {
              businessClose: "",
              businessFreeze: "",
              businessProcess: "",
              businessStop: "",
              changeTime: "",
              contractsCode: "",
              createTime: "",
              freezeName: "",
              freezeTime: "",
              id: "",
              inventoryReturnNum: "",
              isPlanConfirm: "",
              isQuotaGeneration: "",

              materialCode: "",
              materialId: "",
              materialName: "",
              materialReceivedReturnNum: "",
              orderId: "",
              planTrackingCode: "",
              requireDocCode: "",
              requireDocLineCode: "",
              requireFrom: "",
              requireTrackingCode: "",
              sourceDocCode: "",
              sourceDocType: "",
              stopName: "",
              stopTime: "",
              surplusInboundNum: "",
              surplusMaterialReceivedNum: "",
              totalInboundNum: "",
              totalMaterialReceivedNum: "",
              totalMaterialReturnNum: "",
              updateFlag: "",
              userId: "",
            },
            originalContainsTaxPrice: "",
            originalNumber: "",
            page: 0,
            parentMaterial: "",
            price: "",
            pricingNum: "",
            pricingUnit: "",
            purchaseUnit: "",
            ramarks: "",
            receivedFirstTicketsNum: "",
            receivingDept: "",
            relationId: "",
            requireDept: "",
            settlementDept: "",
            sourceDocCode: "",
            sourceDocType: "",
            sourceRelationId: "",
            supplierMaterialCode: "",
            supplierMaterialName: "",
            taxAmount: "",
            taxMoney: "",
            taxPrice: "",
            taxRate: "",
            token: "",
            totalAcceptanceAmount: "",
            totalAcceptanceRate: "",
            totalTaxPrice: "",
            type: 0,
            warehouseId: "",
            warehouseRegionId: "",
          };
          Object.keys(item).forEach((itemKey) => {
            Object.keys(materialObj).forEach((materialKey) => {
              if (itemKey === materialKey) {
                materialObj[materialKey] = item[itemKey];
              }
              if (itemKey === "materialDetailId") {
                materialObj["sourceMaterialDetailId"] =
                  item["materialDetailId"];
              }
              if (itemKey === "id") {
                materialObj["sourceRelationId"] = item["id"];
              }
              if (materialKey === "id") {
                materialObj["id"] = "";
              }
            });
          });
          this.formObject.materialDetailEntities.push(materialObj);
        });
        getOrderDetail(this.selectItem[0].id).then((res) => {
          res.data.supplierName
            ? (this.formObject.contractProcureEntity.supplierName =
                res.data.supplierName)
            : "";
          res.data.supplierId
            ? (this.formObject.contractProcureEntity.supplierId =
                res.data.supplierId)
            : "";
        });
        this.open = false;
      }
    },
    // 弹框取消按钮
    cancelSelect() {
      this.open = false;
      this.selectItem = [];
    },
    // 获取物料
    getMaterialLists(index) {
      this.dialogTitle = "物料列表";
      this.currentIndex = index;
      // 不选单
      getMaterialList().then((res) => {
        if (res.code === 200) {
          this.loading = false;
          this.tableData = res.data.records;
          this.total = res.data.total;
        }
      });
    },
    // 选择物料
    selectMaterialtem(val) {
      this.selectItem = val;
    },

    // 计算值
    caculateNum(row, index) {
      if (row.number && row.taxRate && row.totalTaxPrice) {
        let totalTaxAmount = row.totalTaxPrice;
        let number = row.number;
        let taxRate = row.taxRate;
        getCompute({ number, taxRate, totalTaxAmount }).then((res) => {
          this.$set(
            this.formObject.materialDetailEntities[index],
            "price",
            res.data.price
          );
          this.$set(
            this.formObject.materialDetailEntities[index],
            "amountMoney",
            res.data.amount
          );

          this.$set(
            this.formObject.materialDetailEntities[index],
            "taxAmount",
            res.data.taxAmount
          );

          this.$set(
            this.formObject.materialDetailEntities[index],
            "taxPrice",
            res.data.taxUnitPrice
          );
        });
      }
    },
  },
  created() {
    // 获取合同类型
    getList({
      typeId: 183,
    }).then((res) => {
      if (res.code === 200) {
        this.contractTypeOptions = res.rows.map((item) => {
          return {
            id: item.id,
            value: item.id,
            label: item.tempName,
            content: item.contractTempContent,
          };
        });
      }
    });
    // 获取详情回显
    if (this.id) {
      this.getDetailData(this.id);
    }
  },
  destroyed() {
    this.id = "";
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-table td.el-table__cell div {
  overflow: visible;
}

::v-deep .el-table td.el-table__cell {
  padding-bottom: 20px;
}
</style>
